package com.xs.designs.adapter.demo2;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysLoginService {

    @Autowired
    UserAdapter remoteUserService;

    public UserDTO login(String username, String password) {
        if(StrUtil.isBlank(username)) {
            throw new IllegalArgumentException("用户名不能为空");
        }
        // 远程调用
        UserDTO userDTO= remoteUserService.getUserDetail(username);

        if (userDTO==null) {
            throw new RuntimeException("登录用户：" + username + " 不存在");
        }
        return userDTO;
    }


    // 获取用户信息
    public UserDTO getUserInfo(String username) {
        if(StrUtil.isBlank(username)) {
            throw new IllegalArgumentException("用户名不能为空");
        }
        UserDTO userDTO= remoteUserService.getUserDetail(username);

        if (userDTO==null) {
            throw new RuntimeException("用户：" + username + " 不存在");
        }
        return userDTO;
    }
}
